package com.neusoft.cmsprojects.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.cmsprojects.dao.UserDao;
import com.neusoft.cmsprojects.model.TbUser;

@Service("userservice")
@Transactional
public class UserServiceImpl implements UserService {

	@Resource(name="userdao")
	private UserDao dao;

	@Override
	public TbUser login(TbUser user) {
		
		return dao.login(user);
	}

	@Override
	public void merge(TbUser u) {
		dao.merge(u);
	}

	@Override
	public void updateLoginTime(TbUser user) {
		String hql="update TbUser t set t.clogintime='"+user.getClogintime()+"' where t.cid='"+user.getCid()+"'";
		dao.updateLoginTime(hql);
	}

	@Override
	public boolean save(TbUser user) {
		String hql="from TbUser t where t.cusername='"+user.getCusername()+"'";
		boolean bo=dao.checkUsername(hql);
		if(bo){
			dao.save(user);
			return true;
		}
		return false;
	}

	@Override
	public List<Object> findAll() {
		String hql="from TbUser ";
		
		return dao.queryByHql(hql);
	}

	@Override
	public void delete(TbUser user) {
		dao.delete(user);
	}

	@Override
	public TbUser findById(Integer cid) {
		return dao.findById(cid);
	}

	@Override
	public void update(TbUser user) {
			dao.update(user);
	}
}
